<?php
/*
*	专题列表相关模型
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Special_m extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->table = 'special';
    }
     //文章ajax 分页
    public function ajaxall($where=array(),$field="*",$order='id desc'){
        $pagesize=getConfig('pagesize');
        $this->com_where($where);
        $this->db->select('count(id) as counts');
        $query=$this->db->get($this->table);
        $counts=$query->row_array();

        $page=isset($_REQUEST['page'])?$_REQUEST['page']:1;
        $startRow=$pagesize * ($page - 1);
        $this->com_where($where);
        $this->db->select($field);
        $this->db->order_by($order);
        $this->db->limit($pagesize,$startRow);
        $query2=$this->db->get($this->table);
        $data['list']=$query2->result_array();
        $data['pageshow']=$this->pageajax_show($pagesize,$counts['counts']);
        return $data;
    }
    //查询单条专题信息
    public function sel($where = array(), $field = "*")
    {
        $this->com_where($where);
        $this->db->select($field);
        $query = $this->db->get($this->table);
        $data = $query->row_array();
        return $data;
    }

    //查询所有
    public function sels($where = array(), $field = "*", $order = 'id desc')
    {
        $this->com_where($where);
        $this->db->select($field);
        $this->db->order_by($order);
        $query = $this->db->get($this->table);
        $data = $query->result_array();
        return $data;
    }
    //添加专题
    public function add($data)
    {
        $data['addtime'] = time();
        $this->db->insert($this->table,$data);
        return $this->db->insert_id();
    }

    //编辑专题
    public function edit($where, $data)
    {
        $this->com_where($where);
        $this->db->update($this->table, $data);
        return $this->db->affected_rows();
    }
    //添加文章到专题
    public function addArticles($data)
    {
        $this->db->insert_batch('special_r', $data);
        return $this->db->affected_rows();
    }
    //删除专题
    public function del($where){
        $this->com_where($where);
        $this->db->delete($this->table);
        return $this->db->affected_rows();
    }
}
?>